//
//  MyNavgationController.m
//  shike
//
//  Created by RegentSoft on 2017/4/19.
//  Copyright © 2017年 RegentSoft. All rights reserved.
//

#import "MyNavgationController.h"

@interface MyNavgationController ()

@end

@implementation MyNavgationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    _bar = [[UINavigationBar alloc]init];
//    _bar.userInteractionEnabled = YES;
//    [_bar setBackgroundImage:[UIImage imageNamed:@"top"] forBarMetrics:UIBarMetricsDefault];
//    [self.view addSubview:_bar];

}
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController{
    
    self = [super initWithRootViewController:rootViewController];
    if (self) {
        [self creatView];
        [self setLayout];
    }
    return self;
}
-(void)creatView{
    _bar = [[UINavigationBar alloc]init];
    _bar.userInteractionEnabled = YES;
    _bar.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_bar];
    
    _navigaTitle = [[UILabel alloc]init];
    _navigaTitle.font = [UIFont systemFontOfSize:16.0f];
    _navigaTitle.textAlignment = NSTextAlignmentCenter;
    _navigaTitle.textColor = [UIColor colorWithHexString:@"#323232"];
    [_bar addSubview:_navigaTitle];
    
    _popButton = [[UIButton alloc]init];
    _popButton.backgroundColor = [UIColor clearColor];
    [_popButton setImage:[UIImage imageNamed:@"backbtn"] forState:UIControlStateNormal];
    [_popButton addTarget:self action:@selector(returnButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [_bar addSubview:_popButton];

}
-(void)setLayout{
    _bar.frame = CGRectMake(0, 0, DeviceWidth, 64);
    [_popButton mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.centerY.equalTo(_bar);
        make.left.equalTo(_bar.mas_left).offset(10);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(20);
    }];
    [_navigaTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(_bar.mas_centerX);
        make.centerY.equalTo(_bar.mas_centerY);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(80);;
    }];
}
// 设置导航栏的标题
- (void) setTitleText:(NSString *)titleText{
    
    _navigaTitle.text = titleText;
}
// 返回
- (void)returnButtonClick:(UIButton *)sender{
    
    [self popViewControllerAnimated:YES];
}
// 隐藏自定义导航栏
- (void)setDIYNavigationBarHidden:(BOOL)isHidden{
    
    _bar.hidden = isHidden;
}
@end
